import { getCategoryData } from "@/apis/category"
import { ref, watch } from "vue"
import { useRoute } from "vue-router"
export const useCategory = () => {
  const route = useRoute()
  console.log(route.params.id)

  const categoryList = ref([])
  // 获取分类数据
  const categoryData = async () => {
    const res = await getCategoryData(route.params.id)
    categoryList.value = res.data.result
  }

  // 调用函数
  categoryData()

  // 监听id变化
  watch(
    () => route.params.id,
    () => {
      categoryData()
    }
  )

  return {
    categoryList,
  }
}
